
import java.io.*;
import java.util.Random;

public class Gen {
	
	//values
	private String phrase;
	private int phraseLength;
	private int wordCount;
	private Random randomNumber = new Random();
	
	//IMPORTANT: DATABASE SIZE MUST BE ENTERED, IT IS CURRENTLY NOT CALCULATED 
	private int databaseSize = 5;
	
	//methods
	public Gen(){
		try {
			FileInputStream fin = new FileInputStream("phrases.txt");
		} catch (FileNotFoundException e) {
			phrase = "Error!";
			// TODO Auto-generated catch block
			
		}
		phrase = "How do you like the program so far?";
		phraseLength = phrase.length();
		
		
	}
	public String getPhrase(){
		return phrase;
	}
	
	public int getLength(){
		return phraseLength;
	}
	
	

	public int getWordCount(String pass){
		int pl = 1;
		for(int x=0; x<pass.length(); x++){
			if(pass.charAt(x) == ' ')
				pl++;
		}
		
		wordCount = pl;
		return wordCount;
	}
	
	public void resetPhrase() throws IOException{
		File database = new File("phrases.txt");
		BufferedReader specifiedLine = null;
		
		try{
			specifiedLine = new BufferedReader(new FileReader(database));
			
			int line = 0;
			while(line< randomNumber.nextInt(databaseSize+1)){
				specifiedLine.readLine();
				line++;
				}
			
			phrase = specifiedLine.readLine();
			phraseLength = phrase.length();
		}catch(FileNotFoundException e){
			
		}
		
	}
}
